package com.zpb.framework.handler.exception;

import com.zpb.framework.domain.enums.ResultCodeEnum;
import com.zpb.framework.exception.SystemException;
import com.zpb.framework.domain.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/11
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(SystemException.class)
    public ApiResult systemExceptionHandler(SystemException e) {
        log.error("出现了异常! {}",e);
        return ApiResult.error(e.getCode(),e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public ApiResult exceptionHandler(Exception e) {
        log.error("出现了异常! {}",e);
        return ApiResult.error(ResultCodeEnum.UNKNOWN_ERROR.getCode(), e.getMessage());
    }
}
